package com.tyj.movie.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tyj.movie.entity.City;
import com.tyj.movie.entity.MovieTheatre;
import com.tyj.movie.entity.MovieTheatreBrand;
import com.tyj.movie.entity.MovieTheatreServer;
import com.tyj.movie.mapper.MovieTheatreMapper;
import com.tyj.movie.service.CityService;
import com.tyj.movie.service.MovieTheatreBrandService;

import com.tyj.movie.service.MovieTheatreService;
import com.tyj.movie.to.MovieTheatreTo;
import com.tyj.movie.vo.MovieTheatreVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tyj
 * @since 2021-06-28
 */
@RestController
@RequestMapping("/movie/theatre")
public class MovieTheatreController {

    @Autowired
    CityService cityService;

    @Autowired
    MovieTheatreBrandService movieTheatreBrandService;

    @Autowired
    MovieTheatreService movieTheatreService;


    /**
     * 分页查询电影
     * @return
     */
    @RequestMapping("/movieTheatre/{pageNum}")
    public ModelAndView queryMovieTheatre(@PathVariable("pageNum") Long pageNum){
        ModelAndView modelAndView=new ModelAndView();
        IPage<MovieTheatreVo> page =movieTheatreService.queryMovieTheatre(pageNum);
        modelAndView.addObject("page",page);
        modelAndView.setViewName("movieTheatre");
        return modelAndView;
    }

    /**
     * 添加电影页
     * @return
     */
    @RequestMapping("/movieTheatreAddOrEditor")
    public ModelAndView movieTheatreAddOrEditor(){
        ModelAndView modelAndView=new ModelAndView();

        //获得所在城市
        List<City> citys = cityService.list();
        modelAndView.addObject("citys",citys);
        //获得电影品牌
        List<MovieTheatreBrand> brands = movieTheatreBrandService.list();
        modelAndView.addObject("brands",brands);

        modelAndView.setViewName("movieTheatreAddOrEditor");
        return modelAndView;
    }

    /**
     * 影院添加
     * @return
     */
    @RequestMapping("/add")
    public ModelAndView movieTheatreAdd(MovieTheatreTo movieTheatreTo){
        ModelAndView modelAndView=new ModelAndView();
        movieTheatreService.addMovieTheatre(movieTheatreTo);
        modelAndView.setViewName("redirect:/movie/theatre/movieTheatre/1");
        return modelAndView;
    }

    /**
     * 电影启用
     */
    @GetMapping("/enable/{id}")
    public ModelAndView enable(@PathVariable("id") Long id){
        movieTheatreService.enable(id);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("redirect:/movie/theatre/movieTheatre/1");
        return modelAndView;
    }

    /**
     * 电影禁用
     */
    @GetMapping("/disable/{id}")
    public ModelAndView disable(@PathVariable("id") Long id){
        movieTheatreService.disable(id);
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("redirect:/movie/theatre/movieTheatre/1");
        return modelAndView;
    }

}

